<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="${mapperInterfacePackage}.${className}Mapper">

	<resultMap id="BaseResultMap" type="${entityPackage}.${className}">
		<#list records as rec>
		<#if rec.pk>
		<id column="${rec.fieldName?upper_case}" property="${rec.property}" jdbcType="${rec.jdbcType}" />
		<#else>
		<result column="${rec.fieldName?upper_case}" property="${rec.property}" jdbcType="${rec.jdbcType}" />
		</#if>
		</#list>
	</resultMap>



 <sql id="Base_Column_List" >
  <#list records as rec>
  		  <#if rec_index == 0>
  		${rec.fieldName}
  		  <#else>
  		  ,${rec.fieldName}
  		  </#if>
  		 </#list>
  </sql>

    <!--根据主key查询-->
        <select id="selectByPrimaryKey" parameterType="${entityPackage}.${className}"  resultMap="BaseResultMap">
            SELECT
                ${tablename?upper_case}.*
    	    FROM ${tablename?upper_case}  WHERE  ${pkRecords[0].fieldName?upper_case} = ${"#{"}${pkRecords[0].property}}
        </select>


    <!--插入-->
       <insert id="commonInsert" parameterType="${entityPackage}.${className}">
           INSERT INTO  ${tablename}
           <trim prefix="(" suffix=")" suffixOverrides=",">
                <#list records as rec>
                                    <#if rec_index != 0>
                                 <if test="${rec.property} != null">
                                 ${rec.fieldName?upper_case},
                                 </if>
                                  </#if>
                               </#list>
           </trim>
           <trim prefix="values (" suffix=")" suffixOverrides=",">
               <#list records as rec>
                               <#if rec_index != 0>
                               <if test="${rec.property} != null">
                               ${"#{"}${rec.property}},
                               </if>
                                </#if>
                               </#list>
           </trim>
       </insert>


   <!-- 更新 -->
<update id="updateByPrimaryKeySelective" parameterType="${entityPackage}.${className}" >
        update ${tablename}
        <set >
         <#list records as rec>
                   <#if rec_index != 0>
              <if test="${rec.property} != null">
              ${rec.fieldName?upper_case} = ${"#{"}${rec.property}},
              </if>
                </#if>
         </#list>
        </set>
        where ${pkRecords[0].fieldName?upper_case} = ${"#{"}${pkRecords[0].property}}
 </update>

  <!--修改-->
     <update id="commonUpdate" parameterType="${entityPackage}.${className}">
     	UPDATE
     	    ${tablename?upper_case}
 	    <set >
                <#list records as rec>
                          <#if rec_index != 0>
                     <if test="${rec.property} != null">
                     ${rec.fieldName?upper_case} = ${"#{"}${rec.property}},
                     </if>
                       </#if>
                </#list>
               </set>
         WHERE
            ${pkRecords[0].fieldName?upper_case} = ${"#{"}${pkRecords[0].property}}
 	         <!--AND TO_CHAR(UPDATE_TIME, 'yyyy-mm-dd hh24missxff6') =${"#{"}updateTimeStr}-->
     </update>


     <!--删除-->
      <delete id="commonDelete" parameterType="${entityPackage}.${className}">
      	DELETE
      	FROM
      		${tablename?upper_case}
      	WHERE
           ${pkRecords[0].fieldName?upper_case} = ${"#{"}${pkRecords[0].property}}
           <!--AND TO_CHAR(UPDATE_TIME, 'yyyy-mm-dd hh24missxff6') =${"#{"}updateTimeStr}-->
      </delete>


        <!--分页查询-->
              <select id="listPage" parameterType="${entityPackage}.${className}"" resultMap="BaseResultMap">
              	SELECT *
              	FROM
              	   ${tablename?upper_case}
              	   WHERE 1=1
              	     <#list records as rec>
                         <#if rec_index != 0>
                             <if test="parameter.${rec.property} != null and parameter.${rec.property} != ''">
                                    AND ${tablename?upper_case}.${rec.fieldName?upper_case}=${"#"}{parameter.${rec.property}${"}"}
                              </if>
                         </#if>
                     </#list>
                     <if test="parameter.orders != null and parameter.orders != ''">
                           order by ${r'${parameter.orders}'}
                      </if>
              </select>

</mapper>